package com.mashibing.juc.c_005;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName T01_ReentrantLock
 * @Description 重进入锁
 * @Author xiongwei.wu
 * @Date 2021/7/1 16:01
 **/
public class T01_ReentrantLock {
    synchronized void m1() {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("m1: " + i);

            if (i == 2) {
                m2();
            }
        }
    }

    synchronized void m2() {
        System.out.println("m2...");
    }

    public static void main(String[] args) {
        T01_ReentrantLock t = new T01_ReentrantLock();
        new Thread(t::m1).start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        new Thread(t::m2).start();
    }
}
